package com.lcm.basic.p7.set.bean;

/**
 * @author Coder-lcm
 * @date 2021/4/3
 */
public class TreeSortBean implements Comparable{
    private int num;
    private String name;

    public TreeSortBean(int num, String name) {
        this.num = num;
        this.name = name;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "TreeSortBean{" +
                "num=" + num +
                ", name='" + name + '\'' +
                '}';
    }

    /**
     * 实现了Comparable接口才可以使用TreeSet，因为TreeSet就是看比较器来比对大小从而决定顺序的
     * @param o
     * @return
     */
    @Override
    public int compareTo(Object o) {
        return this.num - ((TreeSortBean) o).num;
    }
}
